package com.hanma.util;

import java.io.FileReader;
import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class DBUtil {
	private static String driver;
	private static String url;
	private static String user;
	private static String password;
	static {
//		Properties prop = new Properties();
//		Reader in;
//		try {
//			in = new FileReader("message/src/main/java\\config.properties");
//			prop.load(in);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		driver=prop.getProperty("driver");
//		url=prop.getProperty("url");
//		user=prop.getProperty("user");
//		password=prop.getProperty("password");
		driver="com.mysql.cj.jdbc.Driver";
		url="jdbc:mysql://localhost:3306/demo1?serverTimezone=GMT%2B8&useSSL=false";
		user="root";
		password="123456";
		
	}
	public static Connection open() {
		try {
			Class.forName(driver);
			return DriverManager.getConnection(url, user, password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public static  void  close(ResultSet rs,Statement sta,Connection conn) {
		if(rs!=null) {
			try {
			rs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}}
		if(sta!=null) {
			try {
				sta.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	}
}
